package com.itool.taglib;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class ConstantTag extends TagSupport {
	private static final long serialVersionUID = 5837278462159215387L;
	
	private String name, var;

	public ConstantTag() {

	}
	@Override
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext
				.getRequest();
		JspWriter out = pageContext.getOut();
		String sConstant = "";
		if (name.equalsIgnoreCase("ContextPath")) {
			sConstant = request.getContextPath();
		}
		if (!sConstant.equals("")) {
			try {
				if (var != null) {
					pageContext.setAttribute(var, sConstant);
				} else {
					out.print(sConstant);
				}
			} catch (Exception e) {
			}
		}
		return 0;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}


}
